package cn.szzsi.business.controller.admin;

import cn.szzsi.common.util.CommonUtil;
import cn.szzsi.model.OperateLogs;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;

import java.util.List;

/**
 * Created by yuanzheng on 2016/12/6.
 */
public class OperateLogsController extends BaseAdminController<OperateLogs> {
    private String shopId;
    public void list(){
        shopId=getAttr("shopId");
        String type=getPara("type");
        int pageNumber=getParaToInt("pageNumber", 1);
        int pageSize=getParaToInt("pageSize", 10);
        StringBuilder sql=new StringBuilder("from sys_operate_logs where uid='"+shopId+"'");
        String username=getPara("username");
        if(StrKit.notBlank(username)){
            sql.append(" and username like '%"+username+"%'");
        }
        if(StrKit.notBlank(type)){
            sql.append(" and type ='"+type+"'");
            setAttr("type",type);
        }
        sql.append(" order by createDate desc ");
        Page<OperateLogs> pager = OperateLogs.dao.paginate(pageNumber,pageSize,"select * ",sql.toString());
        setAttr("pager", pager);
        if("0".equals(type)){
            render(CommonUtil.TEMPLATE_PATH+"/business/operatelogs/operate_login_logs.html");
        }else if("1".equals(type)){
            render(CommonUtil.TEMPLATE_PATH+"/business/operatelogs/operate_other_logs.html");
        }
    }
    //ajax list
    public void ajaxlist(){
        shopId=getAttr("shopId");
        int type=getParaToInt("type");
        List<OperateLogs> lol = OperateLogs.dao.find("select * from sys_operate_logs where uid = ? and type=? order by createDate desc",shopId,type);
        renderJson(lol);
    }
}
